var serverPath = "http://localhost:8888/";
var imageServerPath = "http://localhost:8183/imgs/";

function getSearchParams() {
	var search = location.search.replace("?", "");
	var namePairs = search.split("&");
	var params = {};
	for(var i = 0; i < namePairs.length; i++) {
		var namePair = namePairs[i].split("=");
		params[namePair[0]] = namePair[1];
	}
	return params;
}

$(function() {
	window.loadHead = function() {
		$.get("head.html", function(html) {
			$("body").prepend(html);
			$("#logout").bind("click", function() {
				$.ajax({
					url: serverPath + "user/logout",
					type: "post",
					xhrFields: {
						withCredentials: true
					},
					success: function() {
						location.href = "login.html";
					}
				});

			});
			$.ajax({
				url: serverPath + "user/loginUser",
				type: "get",
				xhrFields: {
					withCredentials: true
				},
				success: function(res) {
					var user = res.data;
					if(user) {
						$("#login,#regist").remove();
						$("#name>a").html(user.name);
					}
				},
				error: function(res) {
					$("#name,#logout").remove();
				}
			});
		});
	}
});